/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 * The pane display a list of project and ask user to select a project name. A project is an analysis seesion.
 * @Original Author: jin Chen
 * @date: Dec 4, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.dataloader.v1.gui;

import epoviz.trex.common.swing.components.filechooser.SingleFileSource;

import javax.swing.*;

public class ProjectNamesPane extends SingleFileSource{
    //ProjectBuilder sesBldr;//=new ProjectBuilder();
    //Project currentSession=new Project();

    public ProjectNamesPane() {
       super();
       //this.setSessionList() ;

    }

     public void setProjectNameEditable(boolean edit) {
        this.fileList.setEditable(edit);
    }
    public void setProjectNames(String [] names){
       fileList.removeAllItems();
       for (int i=0;i<names.length ;i++){
           fileList.addItem(names[i]);
       }
        //this.fileList.setSelectedItem(ProjectBuilder.Project_New);

    }

    protected void initValue() {
        this.fileList.setEditable(true);
        this.name ="Project name ";
        categoryL.setText(this.name );

         //remove button
        this.inputP.remove(openBtn);
        this.inputP.revalidate() ;
        //openBtn.setText("Save");
        //openBtn.setIcon(openImg);

        ImageIcon avaImg=(ImageIcon) this.images.get(IMAGE_NotOK);
        availableL.setText("");
        availableL.setIcon(avaImg);

     }


    /**
     *  invoked upon enter value in JComboBox
     */
    protected void updateAvailability(){
        if(DEBUG)
            System.out.println("updateAvailability "+System.currentTimeMillis() );
        String name=(String) this.fileList.getSelectedItem() ;

        if(name==null||name.trim().equals("") ){
            ImageIcon notok=(ImageIcon) this.images.get(IMAGE_NotOK);
            this.availableL.setIcon(notok);
            //this.setValid(false);

        }
        else{
            ImageIcon ok=(ImageIcon) this.images.get(IMAGE_OK);
            this.availableL.setIcon(ok);
        }
        this.labelP.repaint() ;

    }



    public String getSelectProjectName(){
        String name=(String) this.fileList.getSelectedItem() ;
        if(name==null&&name.trim().equals("") ){
           // name=ProjectBuilder.Project_LastOne;
            name=(String) fileList.getItemAt(0);
        }
        return name;

    }


}
